<template>
    <div class="companyInfoCon">
        <div class="infolist">
          <div class="headerSection">
            <split-vertical title="新公司信息"></split-vertical>
            <v-form :formProps="searchForm" ref="form"
                    v-on:handleReset="handleReset"
                    v-on:coverFormData="coverFormData"></v-form>
          </div>
          <div class="stand">
            <div style="line-height:50px;margin-left:10px;">
              <v-button :operationBtnArray="operationBtnArray" v-on:handleSearchTopBtn="handleSearchTopBtn"></v-button>
            </div>
            <div style="margin:0 10px;">
              <v-table :tableParams="tableParams" v-on:handleOperation="handleOperation"></v-table>
            </div>
          </div>
          <div class="block">
                <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="pageIndex"
                    :page-sizes="[10]"
                    :page-size="10"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageCount">
                </el-pagination>
            </div>
            <!-- //编辑信息 -->
            <addcom-info v-if="show2" :editCompanyInfo='editCompanyInfo' @closeDialog='closeDialog'></addcom-info>
            <!-- 创建信息 -->
            <create-company v-if="show" @closeDialog='closeDialog'></create-company>
        </div>
    </div>
</template>
<script>
import VTable from "components/common/PageTable/VTable"
import createCompany from 'components/base/newCompanyInfo/CreateCompany'
import addcomInfo from 'components/base/newCompanyInfo/AddcomInfo'
import {localStorage} from 'js/localStorage'
import SplitVertical from "components/common/SplitVertical"
import VForm from "components/common/VForm"
import VButton from "components/common/VButton"
export default {
    inject:['reload'],
    data(){
        return{
            id:'',
            row:{},
            searchCondition:{},
            pageIndex:1,
            pageSize:10,
            pageCount:null,
            show:false,//控制创建公司信息的显示
            show2:false,//控制编辑公司信息的显示
            companyName:'',
            companyCode:'',
            accountNo:'',
            editCompanyInfo:{},
            searchForm: {
              col: 3,
              labelWidth: '120px',
              submitBtn: {
                text: '搜索'
              },
              formItemArray: [{
                label: '组织机构编码',
                prop: 'organizationCode',
                placeholder: "请输入组织机构编码",
                value: ''
              }, {
                label: '公司名称',
                prop: 'companyName',
                placeholder: "请输入公司名称",
                value: ''
              }]
            },
            operationBtnArray: [{
              text: '刷新',
              show: true,
              icon:'el-icon-refresh',
              type: 'primary',
              methodName: 'refresh',
            }, {
              text: '新增',
              show: true,
              icon:'el-icon-plus',
              type: 'success',
              methodName: 'add',
            }],
            tableParams:{
                dataArray:[],
                showMultiSelection:false,
                columnArray:[
                    {label: '组织机构编码', prop: 'organizationCode',  sortable: false,width:'130'},
                    {label: '公司名称', prop: 'companyName',  sortable: false},
                    {label: '法人代表', prop: 'legalPersonName',  sortable: false},
                    // {label: '税号', prop: 'tax',sortable: false},
                    // {label: '账号', prop: 'accountNo',sortable: false},
                    // {label: '开户行', prop: 'accountBank',sortable: false},
                    {label: '公司电话', prop: 'companyPhone',sortable: false},
                    {label: '客服电话', prop: 'customerServicePhone',sortable: false},
                    {label: '公司地址', prop: 'companyAddress',sortable: false},

                ],
                rowHandle:{
                    view:{
                        show:false
                    }
                }
            },
        }
    },
    created(){
      this.init()
    },
    methods:{
        init(){
           this.listVal()
        },
        handleSearchTopBtn(methodName) {
          if (methodName === "refresh") {
            this.refresh();
          } else {
            this.create();
          }
        },
        handleReset(formName) {
          this.$refs.form.resetForm(formName);
        },
        coverFormData(data) {
          this.searchCondition = data;
          this.query()
        },
        handleOperation(rowIndex, row, methodName) {
            this.id=row.id;
            this.row=row;
            if(methodName == "update"){
               this.showTip=true
               this.modifyCompanyInfo()
            }else if(methodName == "delete"){
                this.delCompanyInfo()
            }
        },
        //刷新
        refresh(){
            this.listVal()
        },
        // 关闭控制编辑公司信息的显示弹窗
        closeDialog(){
            this.show2 = false;
            this.show = false;
        },
        //初始化新增公司信息的表格
        listVal(){
          let param = this.searchCondition;
          param['page']={
            pageIndex:this.pageIndex,
            pageSize:this.pageSize
          }
            let success=data=>{
                if(data.statusCode == '1'){
                    this.pageCount = data.body.count
                    this.tableParams.dataArray= data.body.records
                }else{
                    this.$message.error(data.msg)
                }
            }
            this.api.enterpriseList(param,success)
        },
        //编辑表格信息
        modifyCompanyInfo(){
            this.show2=true
            let parmas={
               id:this.id
            }
            let success=data=>{
                if(data.statusCode === '1'){
                    this.editCompanyInfo=data.body
                }else{
                    this.$message.error(data.msg)
                }
            }
            this.api.enterpriseGetOne(parmas,success)
        },
        //查询
        query(){
          let param = this.searchCondition;
              param['page']={
                pageIndex:this.pageIndex,
                pageSize:this.pageSize
              }
          let success = data => {
            if (data.statusCode === '1') {
              this.pageCount = data.body.count;
              this.tableParams.dataArray=data.body.records
            } else {
              this.$message.error(data.statusMessage);
            }
          };
          this.api.enterpriseList(param,success)
        },
        //删除表格信息
        delCompanyInfo() {
          this.tips.ConfirmModal('确认要删除【' + this.row.companyName + '】吗？', () => {
            let parmas = {
              id: this.id
            }
            let success = data => {
              if (data.statusCode === '1') {
                this.reload()
                this.$message.success("删除成功")
              } else {
                this.$message.error(data.statusMessage)
              }
            }
            this.api.enterpriseDelete(parmas, success)
          })

        },
        //创建新公司信息
        create(){
            this.show=!this.show;
        },
        //当前页
        handleCurrentChange(val) {
          this.pageIndex=val
          this.query()
        },
    },
    components:{
        createCompany, addcomInfo,VTable,SplitVertical,VForm,VButton
    }
}
</script>

<style lang="scss" scoped>
.companyInfoCon{
   .infolist{
     .headerSection{
       background:#fff;
       height:140px;
       padding:0 10px;
       border-left: 2px solid #e8e8e8;
       border-right: 2px solid #e8e8e8;
       border-bottom: 2px solid #e8e8e8;
     }
     .block{
       padding: 15px;
       text-align: right;
     }
  }
}
</style>
